﻿/*<span name="__V_S" vt="0" elt1="id1" elt2="id2" vc="0" reg="" vg="" style="display:none" class="validMsg"></span>
vt(0规则验证,1对象比较. 如果为其他值，按0处理)可选，如果没有，缺省值为0
elt1（验证元素id，不可缺少）
elt2(比较元素id,当vt为1时必不可少）
vc（0：elt1==elt2，1：elt1>elt2，2：elt1<elt2。当为其他值时或不存在时为0）
reg(vt为0是必不可少，规则表达式）
vg(验证组，用逗号分开，可选。如没有则缺省为0）
*/
function $ValidButton$(group)
{
    var arrList = __V_getElementsByName_iefix("span","__V_S");var k = arrList.length;var arrList1 = new Array();
    var g = 0;
    if(group) g=group;
    g = ","+g+",";
    for(var i=0;i<k;i++)
    {
        var s = "0";
        if(arrList[i].getAttribute("vg")) s = arrList[i].getAttribute("vg");
        s = ","+s+",";
       if(s.indexOf(g)>-1) arrList1[arrList1.length] = arrList[i];
    }
    var flag = true;
    if(arrList1.length>0) flag = __V_ValidArray(arrList1);
    return flag;
}
function __V_ValidArray(arrList)
{
    var flag = true;var flag1 = null;var k = arrList.length;
    for(var i=0;i<k;i++)
    {
        flag1= __V_ValidElement(arrList[i]);
        if(flag&&!flag1) flag = false;
    }
    return flag;
}
function __V_ValidElement(element)
{
    var vt = "0";
    if(element.getAttribute("vt")) vt = element.getAttribute("vt");
    if(vt=="1")
    {
        return __V_ValidElement1(element)
    }
    else
    {
        return __V_ValidElement0(element)
    }
}
function __V_ValidElement0(element)
{
    var flag = true;
    if(element.getAttribute("elt1")&&element.getAttribute("reg"))
    {
        var obj = $(element.getAttribute("elt1"));
        try
        {
            if(obj) flag = __V_RegularValid(obj,element.getAttribute("reg"));
            __V_Show(element,obj,flag);
        }
        catch(e){}
    }
    return flag;
}
function __V_ValidElement1(element)
{
    var flag = true; 
    if(element.getAttribute("elt1")&&element.getAttribute("elt2"))
    {
        var obj1 = $(element.getAttribute("elt1"));var obj2 = $(element.getAttribute("elt2"));
        if(obj1&&obj2)
        {
           var vc = 0;
           if(element.getAttribute("vc")) vc = element.getAttribute("vc");
           if(vc!="0"&&vc!="1"&&vc!="2") vc = "0";
           if(vc=="0") flag = (obj1.value==obj2.value);
           else if (vc=="1") flag = (obj1.value>obj2.value); 
           else if (vc=="2") flag = (obj1.value<obj2.value); 
           __V_Show(element,obj1,flag);
        }
    }
}
function __V_Show(element,obj,flag)
{
    if(flag)
    {
        $RemoveCssClass$(obj, "validatorCalloutHighlight");
        element.style.display = "none";
    }
    else
    {
        $AddCssClass$(obj,"validatorCalloutHighlight");
        element.style.display = "block";
    }
}

function __V_RegularValid(control,reg) 
{
    var value = __V_ValidatorGetValue(control);
    var rx = new RegExp(reg);
    var matches = rx.exec(value);
    return (matches != null && value == matches[0]);
}

function __V_ValidatorGetValue(control) {
    if (typeof(control.value) == "string") {
        return control.value;
    }
    return __V_ValidatorGetValueRecursive(control);
}
function __V_ValidatorGetValueRecursive(control)
{
    if (typeof(control.value) == "string" && (control.type != "radio" || control.checked == true)) {
        return control.value;
    }
    var i, val;
    for (i = 0; i<control.childNodes.length; i++) {
        val = __V_ValidatorGetValueRecursive(control.childNodes[i]);
        if (val != "") return val;
    }
    return "";
}
function __V_getElementsByName_iefix(tag, name) 
{
      var elem = document.getElementsByTagName(tag);
      var arr = new Array();
      for(var i = 0,iarr = 0; i < elem.length; i++) {
           att = elem[i].getAttribute("name");
           if(att == name) {
                arr[iarr] = elem[i];
                iarr++;
           }
      }
      return arr;
 }